//
//  YSSearchProductCell.m
//  Yueshi
//
//  Created by yueshi－mac1 on 16/2/22.
//  Copyright © 2016年 悦食中国. All rights reserved.
//

#import "YSSearchProductCell.h"

@interface YSSearchProductCell()
@property (weak, nonatomic) IBOutlet UIImageView *icon;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *saleNumLabel;

@end

@implementation YSSearchProductCell

+ (instancetype)initWithTableView:(UITableView *)tableView{
    static NSString *ID = @"YSSearchProductCell";
    YSSearchProductCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"YSSearchProductCell" owner:nil options:nil] lastObject];
    }
    return cell;
}

- (void)setInfo:(YSProductList *)info{
    [self.titleLabel setText:info.prodWholeName];
    [self.icon setImageURLStr:info.prodImageUrl];
    
    [self.priceLabel setText:[NSString stringWithFormat:@"¥%.1f",info.prodNewPrice]];
    CGFloat discount =  info.prodNewPrice/info.prodOldPrice;
    if(info.prodPromotion && info.prodPromotion.price){
        discount = info.prodPromotion.price/info.prodOldPrice;
        [self.priceLabel setText:[NSString stringWithFormat:@"¥%.1f",info.prodPromotion.price]];
    }
    
    [self.saleNumLabel setText:[NSString stringWithFormat:@"已售%ld",info.prodBuyCount]];
}

- (void)awakeFromNib {

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
